package com.hujie.sqlqueryes.dto;

import lombok.Data;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.io.Serializable;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class R<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    
    @JsonProperty("success")
    private boolean success;
    
    @JsonProperty("message")
    private String message;
    
    @JsonProperty("data")
    private T data;
    
    public static <T> R<T> success(T data) {
        R<T> r = new R<>();
        r.success = true;
        r.data = data;
        return r;
    }
    
    public static <T> R<T> success(T data, String message) {
        R<T> r = new R<>();
        r.success = true;
        r.data = data;
        r.message = message;
        return r;
    }
    
    public static <T> R<T> error(String message) {
        R<T> r = new R<>();
        r.success = false;
        r.message = message;
        return r;
    }
}